package com.example.seataaccountsys.api;

import com.example.seataaccountsys.service.AccountService;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@Slf4j
@RestController
public class AccountController {

    @Autowired
    AccountService accountService;

    @GetMapping("/account/debit")
    public String debit(@RequestParam Long userId, @RequestParam BigDecimal orderMoney) {
        log.info("account XID " + RootContext.getXID());
        accountService.decrease(userId, orderMoney);
        return "ok";
    }

}